tests: virtual HID device test harness (Linux/Windows/macOS/libusb)#815
tests: virtual HID device test harness (Linux/Windows/macOS/libusb)#815Youw wants to merge 2 commits into
Conversation
|
Great. We need this kind of virtual test device for hidapi (and also libusb). |
1cdc8d5 to
b330600
Compare
|
FYI on WDK, the Windows runners have WDK installed already. Nuget WDK -- smaller but lacking some tools, which may be okay for this purpose Reference: |
5a24890 to
6089973
Compare
|
Thanks @mcuee, that's useful. The This reply was generated by Claude Code at my request. |
https://www.instagram.com/p/DXcOy5riYPS/ (I home community don't mind a little humor here) |
d3877f1 to
35b5186
Compare
|
Followed up on the WDK tip — thanks again. On the current So rather than dropping the download, I cached it. The (The NuGet WDK would be a cleaner long-term route, but it needs reworking the legacy Posted by Claude Code at my request. |
35b5186 to
a0792ee
Compare
Add a reusable harness that runs HIDAPI tests against a *virtual* HID device,
needing no physical hardware. Tests use only the public HIDAPI API plus a
backend-agnostic test_virtual_device interface, so the same test runs against
every backend that ships a virtual-device provider. Devices expose pre-recorded
"scenarios": the test sends a Feature report carrying a command byte and the
device replays the matching canned input report.
- src/tests/test_device_io.c: a simple open -> write -> exchange reports ->
close smoke test (skips via CTest code 77 when no virtual device is present).
- Providers:
test_virtual_device_uhid.c Linux hidraw (kernel /dev/uhid)
test_virtual_device_rawgadget.c Linux libusb (/dev/raw-gadget + dummy_hcd)
test_virtual_device_win.c (+windows/driver/) Windows winapi (vhidmini2 UMDF2)
test_virtual_device_mac.c macOS darwin (IOHIDUserDevice)
Each self-skips when its device can't be created.
- HIDAPI_WITH_TESTS is offered on Linux/macOS too; src/tests builds the test for
whichever backend(s) are present.
- src/tests/README.md documents the providers, the scenario protocol, and why
FreeBSD/NetBSD/OpenBSD have no provider (no userspace HID/USB-create facility).
- src/tests/windows/driver/ vendors a modified Microsoft vhidmini2 UMDF2 sample
under its original Microsoft Public License (MS-PL); LICENSE.txt and README.md
there record the provenance and modifications and keep it separate from
HIDAPI's own license (the driver is a standalone test fixture, not linked into
the library).
Assisted-by: Claude:claude-opus-4.8
- builds.yml: build the test on Linux/Windows/macOS and run it where possible (ubuntu-cmake loads uhid and runs DeviceIO_hidraw; Windows/macOS/libusb build and self-skip), keeping the per-push matrix green. - win-vhid-test.yml: build, self-sign and install the vhidmini2 driver on a hosted windows-latest runner and run DeviceIO_winapi against it. - libusb-vhid-test.yml (+ .github/vmrun-libusb.sh): the hosted kernel has no USB gadget subsystem, so run DeviceIO_libusb inside a virtme-ng VM that boots a generic kernel (building dummy_hcd out-of-tree and loading raw_gadget) against a real virtual USB device. Both privileged jobs run only via workflow_dispatch or a 'ci-virtual-device' pull-request label, so they stay out of the per-push matrix. Assisted-by: Claude:claude-opus-4.8
a0792ee to
3ae4b91
Compare
Summary
Adds a small, reusable virtual HID device test harness so HIDAPI can be tested without physical hardware. Tests are written purely against the public HIDAPI API plus a backend-agnostic
test_virtual_deviceinterface, so the same test runs against every backend that ships a provider.Devices expose pre-recorded scenarios: the test sends a Feature report whose first payload byte is a command, and the device replays the matching canned input report — keeping the test code 100% platform-neutral.
Intended as a foundation further tests can build on (e.g. the
hid_read_interrupttest in #799 can rebase onto this harness).What's here
src/tests/test_device_io.c— a simple open → write → exchange reports (Feature trigger / input read) → close smoke test.test_virtual_device_uhid.c/dev/uhidtest_virtual_device_rawgadget.c/dev/raw-gadget+dummy_hcd, inside a VMlibusb-vhid-test(VM)test_virtual_device_win.c+windows/driver/win-vhid-testtest_virtual_device_mac.cIOHIDUserDevice(IOKit)See
src/tests/README.mdfor details, including why FreeBSD/NetBSD/OpenBSD have no provider (no userspace HID/USB-create facility on any BSD).CI
builds.yml): the test is built on all platforms and run where possible.ubuntu-cmakeloadsuhidand runsDeviceIO_hidrawfor real, whileDeviceIO_libusbbuilds but self-skips there (the hosted kernel has no USB gadget subsystem); Windows and macOS likewise build the test and self-skip — so the matrix stays green everywhere.win-vhid-test.yml(manual): builds, self-signs and installs the vhidmini2 driver on a hostedwindows-latestrunner and runsDeviceIO_winapiagainst the real device. ✅ verified passing.libusb-vhid-test.yml(manual): the hostedubuntu-latest(azure) kernel has no USB gadget subsystem, so this runsDeviceIO_libusbinside a lightweightvirtme-ng+ QEMU VM that boots a generic kernel (buildingdummy_hcdout-of-tree and loadingraw_gadget), against a real virtual USB device. ✅ verified passing. The same approach works locally and on WSL2.The two privileged jobs run only via
workflow_dispatchor when a pull request carries theci-virtual-devicelabel, so they stay out of the per-push matrix.Commits
tests: add a backend-agnostic virtual HID device test harnessci: build and run the virtual HID device testsDrafted with Claude Code.